package deibay.client.core;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JList;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import deibay.client.IModel;
import deibay.client.ItemObject;
import deibay.client.SellerController;
import deibay.client.core.views.IPanelSeller;
import deibay.messages.RequestItemDetailsMsg;
import deibay.messages.RequestSellerItemDetailsMsg;

public class DeibaySellerController extends SellerController{

	public DeibaySellerController(IPanelSeller view, IModel model) {
		super(view, model);
	}

	@Override
	public void initView() {
		this.viewItemDetails = this.view.showItemDetailsView();
	}
	
	@Override
	public void createViewEvents() {
		view.setAddItemAction(new MouseListener()
		{

			public void mouseClicked(MouseEvent arg0) {				
				itemController = new DeibayItemController(view.showAddItemView(), model);				
			}

			public void mouseEntered(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}

			public void mouseExited(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}

			public void mousePressed(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}

			public void mouseReleased(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}
			
		});
		
		view.setSendAdvertiseAction(new MouseListener(){

			public void mouseClicked(MouseEvent arg0) {
				advertiseController = new DeibayAdvertiseController(view.showAdvertiseView(), model);
				
			}

			public void mouseEntered(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}

			public void mouseExited(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}

			public void mousePressed(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}

			public void mouseReleased(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}
			
		});
		
		view.setChangeItemAction(new ListSelectionListener()
		{

			public void valueChanged(ListSelectionEvent arg0) {
				selectedItem = (ItemObject)((JList)arg0.getSource()).getSelectedValue();				
			}
			
		});
		
		view.setClickItemAction(new MouseListener(){

			public void mouseClicked(MouseEvent arg0) {				
				if(arg0.getClickCount() == 2)
				{
					if(selectedItem != null)
					{					
						RequestSellerItemDetailsMsg msg = new RequestSellerItemDetailsMsg(RequestSellerItemDetailsMsg.class.getSimpleName(), (String)selectedItem.getItemId());						
						model.sendMessage(msg);
					}
				}
			}

			public void mouseEntered(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}

			public void mouseExited(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}

			public void mousePressed(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}

			public void mouseReleased(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}
			
		});
	}	

}
